package org.cmcc.pcap.packet.udp;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.pcap4j.packet.UdpPacket;

public class UdpProtocolFilter {
	
	public static Logger logger = LogManager.getLogger(UdpProtocolFilter.class);
	
public static UdpProtocol filterUdpProtocol(UdpPacket udpPacket){
		
		if(udpPacket.length() == 0){//该判断多余0613add
			return null;
		}
		
		//TODO 扫描应用层数据判断协议类型
		//TODO 如何判断HTTP？？？？？HTTP\GET\POST?
		
		
		//parseProtocol(tcpPacketDecorator.tcpPacket.data);  //TODO
		
		//TODO 根据配置决定放回值
		
		String dst_port =  udpPacket.getHeader().getDstPort().valueAsString();
		String src_port =  udpPacket.getHeader().getSrcPort().valueAsString();

/*
		if((dst_port.equals("443") || src_port.equals("443")) && Arrays.asList(PacketAnalysisConfig.getConfigAsString("tcp.protocol.filter").split(",")).contains("https")){
			logger.debug("https filtered");
			return TcpProtocol.HTTPS;
		}
*/
		logger.debug("udp protocol filtered");
		return UdpProtocol.UDP;

		
/*
		if(!((dst_port.equals("443") || src_port.equals("443")) && Arrays.asList(PacketAnalysisConfig.getConfigAsString("tcp.protocol.filter").split(",")).contains("https"))
			&& !(parseProtocol(tcpPacketDecorator.getData(1)) == TcpProtocol.HTTP && Arrays.asList(PacketAnalysisConfig.getConfigAsString("tcp.protocol.filter").split(",")).contains("http"))){
			logger.debug("tcp filtered");
			return TcpProtocol.TCP;
		}
		return null;
*/

	}

}
